package com.newsmanagement.controller.admin;

import com.newsmanagement.domain.pojo.Admin;
import com.newsmanagement.domain.pojo.NodeInfo;
import com.newsmanagement.domain.pojo.Result;
import com.newsmanagement.service.AdminService;
import jakarta.validation.constraints.Pattern;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private AdminService adminService;
    /**
     * 节点企业登录
     * @param username
     * @param password
     * @return
     */
    @PostMapping("/login")
    public Result<String> login(@Pattern(regexp = "^\\S{5,16}$") String username, @Pattern(regexp = "^\\S{5,16}$") String password) {
        //根据用户名查询用户
        Admin admin = new Admin();
        admin.setAdminName(username);
        admin.setAdminPassword(password);
        String token = adminService.adminLogin(admin);
        if (token == null){
            return Result.error("密码错误");
        }
        return Result.success(token);
    }


}
